<?php namespace Wx\Controller;

use Hdphp\Controller\Controller;

class MenuController extends Controller
{
  //GET /photo 索引
  public function index()
  {
    $menu = Api('Menu/getListMenu');
    $this->assign('menu', $menu);
    // var_dump($menu);die;
    $this->display();
  }

  //DELETE /photo/{photo} 删除单一菜单
  public function destroy()
  {
    $re = Api('Menu/destroy', array($_GET['id']));
    if ($re)
    {
      $json = array(
        'status'    => 1,
        'lastid'    => $re[1],
        'pid'    => $re[2],
        'content' => '删除成功'
        );
    }
    else
    {
      $json = array(
        'status'    => 0,
        'pid'    => 0,
        'content' => Api('Menu/getError')
        );
    }
    // var_dump($json);die;
    $this->ajax($json);
  }

  //删除父级分类以及其下的子分类
  public function delAll(){
    if(Api('Menu/del_all',array($_POST['id'])))
    {
      $json = array(
        'status'    => 1,
        'content' => '删除成功'
        );
    }
    else
    {
      $json = array(
        'status'    => 0,
        'content' => '删除失败'
        );
    }
    $this->ajax($json);
  }

  //POST /photo 保存新增数据
  public function store()
  {
    if (Api('Menu/store'))
    {
      $json = array(
        'status'    => 1,
        'content' => '添加成功'
        );
    }
    else
    {
      $json = array(
        'status'    => 0,
        'content' => Api('Menu/getError')
        );
    }
    $this->ajax($json);
  }

  //PUT /photo/{photo} 更新数据
  public function update($id) 
  {
    if (Api('Menu/update',array($id)))
    {
      $json = array(
        'status'    => 1,
        'content' => '更新成功'
        );
    }
    else
    {
      $json = array(
        'status'    => 0,
        'content' => Api('Menu/getError')
        );
    }
    $this->ajax($json);
  }

  //生成
  public function push()
  {
    if(Api('Menu/push'))
    {
      $json = array(
        'status'    => 1,
        'content' => '生成成功！'
        );
    }
    else
    {
      $json = array(
        'status'    => 0,
        'content' => '生成失败！'
        );
    }
    $this->ajax($json);
  }

  //生成
  public function revoke()
  {
    if(Api('Menu/revoke'))
    {
      $json = array(
        'status'    => 1,
        'content' => '撤销成功！'
        );
    }
    else
    {
      $json = array(
        'status'    => 0,
        'content' => '撤销失败！'
        );
    }
    $this->ajax($json);
  }


  //GET /photo/create 创建界面
  public function create()
  {

  }


  //GET /photo/{photo} 显示文章
  public function show()
  {

  }

  //GET /photo/{photo}/edit 更新界面
  public function edit($id)
  {
    
  }


}